﻿<!DOCTYPE HTML>
<html>
{include file="public:header_css"}
<link href="__STATIC__/admin/lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<body>

<nav class="breadcrumb">
	<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 文章列表 <span class="c-gray en">&gt;</span> 添加文章
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
</nav>

<div class="page-container">

	<form action="" method="post" class="form form-horizontal" id="form-article-add" enctype="multipart/form-data" name="myForm">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章标题：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="请输入文章标题" id="title" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>作者：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="{$author}" placeholder="" id="author" name="author">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章分类：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<span class="select-box">
				<select name="sort" class="select" id="sort">
					<option value="sel">请选择分类</option>
					{foreach name="sort" item="v" key="k"}
					<option value="{$v.sort}">{$v.sort}</option>
					{/foreach}
				</select>
				</span>
			</div>
		</div>

		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>文章内容：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<script id="editor" type="text/plain" style="width:100%;height:400px;"></script>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<a class="btn btn-primary radius" id="submit">&nbsp;&nbsp;提交&nbsp;&nbsp;</a>
				<a class="btn btn-warning radius" href="{:url('index')}">&nbsp;&nbsp;取消&nbsp;&nbsp;</a>
			</div>
		</div>
	</form>

</div>
{include file="public:footer_js"}

<script type="text/javascript" src="__STATIC__/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript" src="__STATIC__/admin/lib/webuploader/0.1.5/webuploader.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/admin/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__STATIC__/admin/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">

        var ue = UE.getEditor('editor',{
            toolbars:[
                [
                    'fullscreen','source','|','undo','redo','|',
					'bold','italic','underline','fontborder','striethrough','superscript',
					'subscript','removeformat','formatmath','autotypeset','blockquote',
					'pasteplain','|','forecolor','backcolor','insertorderedlist',
					'insertunorderedlist','selectall','cleardoc','|',
					'rowspacingtop','rowspacingbottom','lineheight','|','imagenone','imageleft','imageright',
					'imagecenter','simpleupload','insertimage','|',
				]
			],
		});
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        // 提交数据
		$("#submit").click(function () {

            var title 		= $("#title").val();
            var sort 		= $("#sort").val();
            var content = ue.getContent()
            var author = $("#author").val();
			console.log(content+"555");
            // 标题不可为空
            if(title === '' || title === "undefined"){
                layer.msg("请填写标题",{icon:5,time:1000});
                $("#title").focus();
                return;
            }

            // 作者不可为空
            if(author === '' || author === "undefined"){
                layer.msg("请填写作者",{icon:5,time:1000});
                $("#author").focus();
                return;
            }
            // 分类不可为空
            if(sort === '' || sort === "sel"){
                layer.msg("请选择分类",{icon:5,time:1000});
                $("#sort").focus();
                return;
            }
            // 文章内容不可为空
            if(content === '' || content === "undefined"){
                layer.msg("请填写文章内容",{icon:5,time:1000});
                UE.getEditor('editor').focus();
                return;
            }


            // 上传数据整理
            var fm = new FormData();

            fm.append('title',title);
            fm.append('sort',sort);
            fm.append('content',content);
            fm.append('author',author);

            // 异步提交
            $.ajax( {
                url:'add_article',
                type:'POST',
                data: fm,
                contentType:false,
                processData:false,
                success:function (res) {
                    if(res.code === 1){
                        layer.msg(res.msg,{icon:6,time:1000});

                        // 两秒后跳转到列表页
                        setTimeout(function () {
                            // location.replace(location.href);
							location.href="{:url('index')}";
                        },2000);

                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                    }
                }
            } );

        });

    });
</script>

</body>
</html>